/**
 * @file       MainPanel.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Feb 3, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "MainPanel.h"
#include "Label.h"
#include "errorcode.h"
#include "Rect.h"
#include "PageInfo.h"
#include "KeyboardListener.h"
#include "MainMenuPanel.h"
#include <cstdio>
#include "TimeLabel.h"

CMainPanel::CMainPanel()
{
}

CMainPanel::~CMainPanel()
{
}

int CMainPanel::onCreate()
{
	readSystemConfigInfo();
	return CPanel::onCreate();
}

int CMainPanel::onEnterKeyPress()
{
	//Press Enter to change to  the main menu  panel
	int iRet = ERR_SUCCESS;
	CMainMenuPanel *pMainMenuPanel = NULL;

	OBJ_NEW(CMainMenuPanel, pMainMenuPanel);
	if (ERR_SUCCESS
			!= (iRet = pMainMenuPanel->create("MainMenuPanel", DEFAULT_RECT,
					this)))
	{
		OBJ_DELETE(pMainMenuPanel);
		return iRet;
	}

	return pMainMenuPanel->show();
}

int CMainPanel::onEscKeyPress()
{
	// Press Esc to return to first page
	this->getPageInfo().setCurPage(1);
	this->getPageInfo().setDirection(CPageInfo::UNKNOW);
	this->invalidate();
	return ERR_SUCCESS;
}

int CMainPanel::onUpKeyPress()
{
	//Press  the up or down buttons to display detail system status
	return CPanel::onUpKeyPress();
}

int CMainPanel::onDownKeyPress()
{
	//Press  the up or down buttons to display detail system status
	return CPanel::onDownKeyPress();
}

void CMainPanel::readSystemConfigInfo()
{
	this->cleanChildObject();

	//TODO: read the base system cfg here and add the object to panel
	CLabel *pLabel = NULL;
	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Name", CRect(0, 0, LCD_WIDTH, 1));
	pLabel->setText("Name:    Netgear System");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Mode", CRect(0, 1, LCD_WIDTH, 1));
	pLabel->setText("Mode:    NAT");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Time", CRect(0, 2, 5, 1));
	pLabel->setText("Time:");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Time", CRect(0, 2, 5, 1));
	pLabel->setText("Time:");
	this->add(pLabel);

	OBJ_NEW(CTimeLabel, pLabel);
	pLabel->create("curTime", CRect(9, 2, LCD_WIDTH - 9, 1));
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Status", CRect(0, 3, LCD_WIDTH, 1));
	pLabel->setText("Status:  UP");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("UpTime", CRect(0, 4, LCD_WIDTH, 1));
	pLabel->setText("UpTime:");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("UpTimeDetail", CRect(8, 5, LCD_WIDTH, 1));
	pLabel->setText("100 Days 10 Hours 10 Mins");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Firmware", CRect(0, 6, LCD_WIDTH, 1));
	pLabel->setText("Firmware:  x.x.x");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("LastUpdate", CRect(0, 7, LCD_WIDTH, 1));
	pLabel->setText("LastUpdate:");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("LastUpdate", CRect(8, 8, LCD_WIDTH, 1));
	pLabel->setText("2011-07-29 06:39:31");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("Author", CRect(0, 9, LCD_WIDTH, 1));
	pLabel->setText("Author: Huabo Zheng");
	this->add(pLabel);

	OBJ_NEW(CLabel, pLabel);
	pLabel->create("page3", CRect(0, 16, LCD_WIDTH, 1));
	pLabel->setText("Page 3: Huabo Zheng");
	this->add(pLabel);

}

